<template>
  <div class="relative h-screen w-screen overflow-hidden">
    <div class="absolute inset-0 z-10">
      <BMap @info-window-btn-click="handleInfoWindowBtnClick" />
    </div>
    <ChatWindow
      ref="chatWindowRef"
      v-model:isVisible="isChatVisible"
      @close="toggleChat"
    />
    <ChatToggleButton v-model:isVisible="isChatVisible" @toggle="toggleChat" />
    <InvestmentDialog ref="investmentDialogRef" />
    <DataAnalysisDialog ref="dataAnalysisDialogRef" />
  </div>
</template>

<script setup>
import { ref } from "vue";
import ChatWindow from "@/components/chat/ChatWindow.vue";
import ChatToggleButton from "@/components/chat/ChatToggleButton.vue";
import BMap from "~/components/bmap/index.vue";
import InvestmentDialog from "~/components/investment-dialog/index.vue";
import DataAnalysisDialog from "~/components/data-analysis-dialog/index.vue";
import { useCompanyStore } from "@/stores/company";

const isChatVisible = ref(false);
const chatWindowRef = ref(null);
const investmentDialogRef = ref(null);
const dataAnalysisDialogRef = ref(null);
const companyStore = useCompanyStore();

onMounted(() => {
  companyStore.getCompanyList();
});

function toggleChat() {}

const handleInfoWindowBtnClick = (type, item) => {
  switch (type) {
    case "产业图谱分析":
      chatWindowRef.value.openMermaidDialog(item);
      $eventBus.emit("location-open", item);
      break;
    case "招商建议":
      console.log("招商建议");
      investmentDialogRef.value.open(item);
      break;
    case "数据分析":
      console.log("数据分析");
      dataAnalysisDialogRef.value.open(item);
      break;
    case "自由对话":
      console.log("自由对话");
      isChatVisible.value = true;
      break;
    default:
      break;
  }
};
</script>
